package gameStates.passes;

import gameStates.ShadowState;
import gameStates.PassGameState;
import gameStates.gui.GUIState;

import com.jme.renderer.Renderer;
import com.jme.renderer.pass.RenderPass;
import com.jmex.game.state.GameState;

public class BasicGameStatePass extends RenderPass {
	
	private static final long serialVersionUID = 1L;
	
	private GameState state;
	
	public BasicGameStatePass() {}
	
	public void setState(PassGameState gs) {
	    state = gs;
	    add(gs.getRootNode());
	}
	
	@Override
	protected void doUpdate(float tpf) {
	    state.update(tpf);
	}
	
	@Override
	public void doRender(Renderer r) {
		if(state instanceof GUIState || state instanceof ShadowState) state.render(0);
		else super.doRender(r);
	}
	
	public GameState getGameState() { return state; }
	
	@Override
	public void cleanUp() {
		super.cleanUp();
		if(state != null) state.cleanup();
	}
}